/*include:js\declare*/
/*include:js\defaultInput*/
/*include:searchPopup*/
var SearchInput=function()
	{
	this.GetArgument(arguments[0],{Id:null,Event:null,IsGetOnly:0,IsSearchPath:0,MaxLength:0,Left:0,Top:0});
	this.SearchFunction=fastCSharp.ThisFunction(this,this.Search);
	this.HideFunction=fastCSharp.ThisFunction(this,this.Hide);
	this.KeyUpFunction=fastCSharp.ThisEvent(this,this.KeyUp);
	this.CheckFunction=fastCSharp.ThisFunction(this,this.CheckDefaultValue);
	this.SetHideFunction=fastCSharp.ThisFunction(this,this.SetHide);
	if(this.MaxLength)	fastCSharp.$Id(this.Id).Set('maxLength',this.MaxLength);
	this.Popup=SearchPopup.Get(arguments[0]);
	this.Popup.GetXY=fastCSharp.ThisFunction(this,this.GetXY);
	this.Query=this.Popup.Query;
	this.Start(this.Event||{IsGetOnly:1});
	};
(fastCSharp.Functions.SearchInput=SearchInput).Inherit(fastCSharp.BaseFunction,{
Start:function(Event)
	{
	if(!Event.IsGetOnly)
		{
		var Element=fastCSharp.$Id(this.Id),Input=Element.Element();
		if(Input!=this.Element)
			{
			this.Element=Input;
			Element.AddEvent('keyup,keypress',this.KeyUpFunction).AddEvent('focus',this.CheckFunction).AddEvent('blur',this.SetHideFunction);
			}
		}
	},
GetValue:function()
	{
	var Input=fastCSharp.DefaultInputs[this.Id];
	return (Input?Input.GetValue():fastCSharp.$Value(this.Id)).Trim();
	},
CheckDefaultValue:function()
	{
	if(this.SearchInterval)	clearTimeout(this.SearchInterval);
//	if(this.$Value(this.Id).Trim()==this.DefaultValue)	this.$Id(this.Id).Value(this.DefaultFocusValue);
	this.Search();
	},
KeyUp:function(Event)
	{
	var Key=Event.keyCode;
	if(!Event.shiftKey&&(Key==38||Key==40))
		{
		Event.CancelBubble();
		this.Popup.MoveIndex(Key-39);
		}
	else if(Key==13&&this.$Id(this.Id).TagName()=='input')
		{
		Event.CancelBubble();
		if(!this.Popup.KeyEnter()&&this.IsSearchPath)	this.Popup.SearchPath(this.GetValue());
		}
	else	{
		if(this.SearchInterval)	clearTimeout(this.SearchInterval);
		this.SearchInterval=setTimeout(this.SearchFunction,200);
		}
	},
GetXY:function()
	{
	var Input=this.$Id(this.Id),XY=Input.XY();
	XY.Left+=this.Left;
	XY.Top+=Input.Height()+this.Top;
	return XY;
	},
SetHide:function()
	{
	if(this.SearchInterval)	clearTimeout(this.SearchInterval);
	this.SearchInterval=setTimeout(this.HideFunction,1000);
	},
Search:function()
	{
	this.Popup.Search(this.GetValue());
	},
Hide:function()
	{
	if(this.SearchInterval)	clearTimeout(this.SearchInterval);
	this.Popup.Hide();
//	if(this.$Value(this.Id).Trim()=='')	this.$Id(this.Id).Value(this.DefaultValue);
	},
GetItem:function(IsValue)
	{
	return this.Popup.GetItem(IsValue);
	},
Clear:function()
	{
	this.Popup.Values=[];
	}
		});
fastCSharp.Object.push(SearchInput);
new fastCSharp.Declare('SearchInput','focus','Src');